package com.example.base;

import com.example.entity.Texample;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 功能描述
 *
 * @author Lockon.wang
 */
public class TestOdd {


    public static void main(String[] args) {
        List<Texample> menuParamList = new ArrayList();


        Texample texample = new Texample();
        texample.setRangeLeft(0L);
        texample.setRangeRight(1000L);
        texample.setPercent(1L);
        texample.setMenuId("1");
        texample.setVolume(new BigDecimal("0"));
        menuParamList.add(texample);
        texample = new Texample();
        texample.setRangeLeft(1000L);
        texample.setRangeRight(2000L);
        texample.setPercent(20L);
        texample.setMenuId("2");
        texample.setVolume(new BigDecimal("200"));
        menuParamList.add(texample);
        texample = new Texample();
        texample.setRangeLeft(2000L);
        texample.setRangeRight(3000L);
        texample.setPercent(30L);
        texample.setMenuId("1");
        texample.setVolume(new BigDecimal("100"));
        menuParamList.add(texample);

       /* String childMenuId = menuParamList.stream().filter(r -> "position_detail".equals(r.getCode())).map(x -> x.getMenuId())
                .findFirst().orElseGet(()->"-1");
        System.out.println(childMenuId);
        BigDecimal allRepayment = BigDecimal.ZERO;

        System.out.println(allRepayment.setScale(2, BigDecimal.ROUND_DOWN));*/

        menuParamList = menuParamList.stream().sorted(Comparator.comparing(Texample::getRangeLeft)).collect(Collectors.toList());
        menuParamList.forEach(v -> v.setId(0L));
        Long volume = 3600L;
        List<Double> doubleList = new ArrayList<>();
        Long finalVolume = volume;
        for (Texample vo : menuParamList) {
            Long tempV = vo.getRangeRight() - vo.getRangeLeft();
            if (tempV.compareTo(volume) >= 0) {
                vo.setId(volume);
                doubleList.add(vo.getId() * vo.getPercent()/100D);
                break;
            }else{
                vo.setId(tempV);
                doubleList.add(vo.getId() * vo.getPercent()/100D);
                volume -= tempV;
            }
        }
        //menuParamList.forEach(r -> System.out.println(r));
        //System.out.println(finalVolume);
        double allD =  doubleList.stream().mapToDouble(r->r.doubleValue()).sum();
        System.out.println(allD/finalVolume);
        System.out.println(new BigDecimal(String.valueOf(allD / finalVolume)).setScale(4,RoundingMode.HALF_UP));
        System.out.println(menuParamList.stream().mapToDouble(r->r.getVolume().doubleValue()).sum());
        menuParamList.stream().forEach(r-> System.out.println(r.getVolume().negate()));
        String a = "T";

        if (!("A".equals(a) || "N".equals(a) || "T".equals(a))) {
            System.out.println("1");
        }else{
            System.out.println("2");
        }

        Map<String,Texample> texampleMap = menuParamList.stream().collect(Collectors.toMap(Texample::getMenuId, Function.identity(), (key1, key2) -> key2));
        System.out.println(texampleMap);
        Integer a1 = 100;
        BigDecimal bb = new BigDecimal("100");
        System.out.println("a1==bb结果=" + (a1 == bb.doubleValue()));

        Integer a2 = new Integer(1010);
        Integer b = 100;
        int c = 1010;
        Integer d=100;
        System.out.println("a == b:"+(a2 == b));
        System.out.println("a == c:"+(a2 == c));
        System.out.println("b == c:"+(b == c));
        System.out.println("b == d:"+(b == d));
        System.out.println("a == d:"+(a2 == d));
        System.out.println("texample===>"+texample);
        Texample v1 = texample;
        v1.setMenuId("vvvvvvvvvvvvvvvvv");
        System.out.println("texample2222222===>"+texample);
        System.out.println("v1===>"+v1);
    }
}
